package dao;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.classic.Session;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;

import to.Matric_disciplina;
import to.QuestaoAvaliacao;
import util.HibernateUtil;

public class PreenchimentoDAO {

	public List<QuestaoAvaliacao> buscarQuestoesAlunos() throws Exception {

		List<QuestaoAvaliacao> listaRetorno = null;

		try {

			Session session = HibernateUtil.getSessionFactory().openSession();
			Criteria criteria = session.createCriteria(QuestaoAvaliacao.class)
					.createAlias("questao", "q").createAlias("avaliacao", "a");
			criteria.add(Restrictions.like("q.tipo", "%Aluno%"));
			criteria.add(Restrictions.like("a.status", "%Ativa%"));
			criteria.addOrder(Order.asc("questao"));
			listaRetorno = (List<QuestaoAvaliacao>) criteria.list();

		} catch (Exception e) {
			e.printStackTrace();
		}

		return listaRetorno;

	}

	public List<Matric_disciplina> buscarTurmasPorAluno() {

		List<Matric_disciplina> listaTurma = null;

		try {

			Session session = HibernateUtil.getSessionFactory().openSession();
			Criteria criteria = session.createCriteria(Matric_disciplina.class,
					"mt").createAlias("turma", "t");
			criteria.addOrder(Order.asc("t.id"));
			listaTurma = (List<Matric_disciplina>) criteria.list();

		} catch (Exception e) {
			e.printStackTrace();
		}

		return listaTurma;

	}
	
	public Matric_disciplina buscarPorMatricula(Integer matricula){
		
		Matric_disciplina mt = new Matric_disciplina();
		
		try {
			
		Session session = HibernateUtil.getSessionFactory().openSession();
		Criteria criteria = session.createCriteria(Matric_disciplina.class, "mtd");
		criteria.add(Restrictions.eq("mtd.matricula",matricula));
		mt = (Matric_disciplina) criteria.uniqueResult();	
		
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return mt;
		
	}

}
